package com.cy.helmet;

import android.app.Application;
import android.os.FileObserver;

import com.cy.helmet.utils.RecursiveFileObserver;
import com.nan.gbd.library.utils.Logger;

import java.util.Observable;
import java.util.Observer;

/**
 * @author NanGBD
 * @date 2020.6.8
 */
public class HelmetApplication extends Application implements Observer {

    private static HelmetApplication mApplication;

    public static HelmetApplication getNanApplication() {
        return mApplication;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApplication = this;
//        BaseAppContext.setmAppContext(mApplication);
//        File file = LocalFileManager.getInstance().getOrCreateMediaFile("config");
//        RecursiveFileObserver.getInstance().push(file.getAbsolutePath());
//        RecursiveFileObserver.getInstance().setObserver(this);
//        RecursiveFileObserver.getInstance().startWatching();


    }

    @Override
    public void update(Observable o, Object arg) {
        if (arg instanceof RecursiveFileObserver.FileEvent) {
            int event = ((RecursiveFileObserver.FileEvent) arg).event;
            String fileName = ((RecursiveFileObserver.FileEvent) arg).fileName;

            switch (event) {
                case FileObserver.MODIFY:
                    //查看是否被调试
                    Logger.i("MODIFY(" + event + "): " + fileName);
                    break;
                case FileObserver.CREATE:
                    //查看是否被调试
                    Logger.i("CREATE(" + event + "): " + fileName);
                    break;
                case FileObserver.DELETE:
                    //查看是否被调试
                    Logger.i("DELETE(" + event + "): " + fileName);
                    break;
                case FileObserver.MOVED_TO:
                    //查看是否被调试
                    Logger.i("MOVED_TO(" + event + "): " + fileName);
                    break;
                default:
                    Logger.i("DEFAULT(" + event + "): " + fileName);
                    break;
            }
        }
    }
}
